﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace Steam_Backup
{
    public class Settings
    {
        private const string m_szFileNameConfig = "config.xml";

        public string SteamLocation
        {
            get { return m_szSteamLocation; }
            set { m_szSteamLocation = value; }
        }
        private string m_szSteamLocation = string.Empty;
        

        public string BackupLocation
        {
            get { return m_szBackupLocation; }
            set { m_szBackupLocation = value; }
        }
        private string m_szBackupLocation = string.Empty;

        
        public List<GameEntry> GameEntries
        {
            get { return m_gameEntries; }
            set { m_gameEntries = value; }
        }
        private List<GameEntry> m_gameEntries = new List<GameEntry>();

        public bool AddGame(GameEntry a_gameEntry)
        {
            GameEntries.Add(a_gameEntry);
            return true;
        }

        public void SaveSettings()
        {
            using(StreamWriter file = new StreamWriter(m_szFileNameConfig))
            {
                XmlSerializer writer = new XmlSerializer(typeof(Settings));
                writer.Serialize(file, this);
                file.Close();
            }
        }

        public static Settings LoadSettings()
        {
            if (!File.Exists(m_szFileNameConfig))
            {
                return new Settings();
            }

            using (StreamReader file = new StreamReader(m_szFileNameConfig))
            {
                XmlSerializer reader = new XmlSerializer(typeof(Settings));
                // Deserialize the content of the file into a Book object.
                return (Settings)reader.Deserialize(file);
            }
        }
    }
}
